/**
 * 771. 宝石与石头
 * https://leetcode-cn.com/problems/jewels-and-stones/
 */
public class Solutions_771 {
    public static void main(String[] args) {
//        String J = "aA", S = "aAAbbbb";  // output: 3
        String J = "z", S = "ZZ";  // output: 0

        int result = numJewelsInStones(J, S);
        System.out.println(result);
    }

    public static int numJewelsInStones(String J, String S) {
        int res = 0;
        if (J == null || J.isEmpty()) {
            return res;
        }
        if (S == null || S.isEmpty()) {
            return res;
        }
        // map[65] = 3, 字符 'A' 在 S 中出现了 3 次
        int[] map = new int[128];
        for (int i = 0; i < S.length(); i++) {
            map[S.charAt(i)] ++;
        }
        for (int i = 0; i < J.length(); i++) {
            // 是“宝石”，则加上出现的次数
            res += map[J.charAt(i)];
        }
        return res;
    }
}
